package com.solo.game.snake;

import java.awt.Color;
import java.io.Serializable;


/**
 * 
 *  <code>Configuration</code>
 *  <p>Configuration描述: 配置
 *  
 *  @version 1.0 
 *  @author Zangrong.Solo 
 *  日期: Dec 13, 2012 3:07:33 PM
 */
public class Preference implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = 1439962518101098264L;

    // 蛇的颜色
    private Color snakeColor;
    
    private Color snakeHeadColor;
    // 背景颜色
    private Color groundColor;
    // 奖励颜色
    private Color bonusColor;
    // 行数
    private int row;
    // 列数
    private int column;
    // 单元格边长
    private int length;
    // 是否有边界
    private boolean infinite;
    // 自动保存录像
    private boolean autoRecord;
    // 游戏速度
    private int speed;
    
    // 执行周期，毫秒，数字越大速度越慢
    private int period;
    
    // 初始蛇身长度
    private int snakeLength;
    
    private static Preference defaultPreference; 
    
    /**
     * 
     * <P>描述: 获取默认配置 TODO
     * 
     * @author Zangrong.Solo
     * 日期: Dec 13, 2012 4:16:31 PM
     * @return
     */
    public static Preference getDefault()
    {
        if (defaultPreference == null) {
            defaultPreference = new Preference();
            
            defaultPreference.setInfinite(false);
            // TODO 自动记录录像暂时不支持该功能
            defaultPreference.setAutoRecord(false);
            defaultPreference.setRow(15);
            defaultPreference.setColumn(15);
            defaultPreference.setLength(15);
            defaultPreference.setSpeed(1);
            defaultPreference.setSnakeLength(6);
            defaultPreference.setPeriod(100);
            
            defaultPreference.setSnakeColor(Color.BLACK);
            defaultPreference.setBonusColor(Color.RED);
            defaultPreference.setGroundColor(Color.WHITE);
            defaultPreference.setSnakeHeadColor(Color.BLACK);
            
        }
        return defaultPreference;
    }
    
    public static void save(Preference preference)
    {
        // TODO 对象序列化
    }
    
    /**
     * 
     * <P>描述: TODO 按用户方式存取配置
     * 
     * @author Zangrong.Solo
     * 日期: Dec 19, 2012 9:58:29 AM
     * @return
     */
    public static Preference load()
    {
        // 获取用户配置 TODO
        Preference userPreference = null;
        if (userPreference == null) {
            userPreference = getDefault();
            // TODO 保存该配置
            
        }
        return userPreference;
    }
    
    public Color getSnakeColor() {
    
        return snakeColor;
    }
    
    public Color getSnakeHeadColor() {
    
        return snakeHeadColor;
    }

    public void setSnakeHeadColor(Color snakeHeadColor) {
    
        this.snakeHeadColor = snakeHeadColor;
    }


    public void setSnakeColor(Color snakeColor) {
    
        this.snakeColor = snakeColor;
    }

    
    public Color getGroundColor() {
    
        return groundColor;
    }

    
    public void setGroundColor(Color groundColor) {
    
        this.groundColor = groundColor;
    }

    
    public Color getBonusColor() {
    
        return bonusColor;
    }

    
    public void setBonusColor(Color bonusColor) {
    
        this.bonusColor = bonusColor;
    }

    
    public int getRow() {
    
        return row;
    }

    
    public void setRow(int row) {
    
        this.row = row;
    }

    
    public int getColumn() {
    
        return column;
    }

    
    public void setColumn(int column) {
    
        this.column = column;
    }

    
    public int getLength() {
    
        return length;
    }

    
    public void setLength(int length) {
    
        this.length = length;
    }

    
    public boolean isInfinite() {
    
        return infinite;
    }

    
    public void setInfinite(boolean infinite) {
    
        this.infinite = infinite;
    }

    
    public boolean isAutoRecord() {
    
        return autoRecord;
    }

    
    public void setAutoRecord(boolean autoRecord) {
    
        this.autoRecord = autoRecord;
    }

    
    public int getSpeed() {
    
        return speed;
    }

    
    public void setSpeed(int speed) {
    
        this.speed = speed;
    }

    
    public int getSnakeLength() {
    
        return snakeLength;
    }

    
    public void setSnakeLength(int snakeLength) {
    
        this.snakeLength = snakeLength;
    }

    
    public int getPeriod() {
    
        return period;
    }

    
    public void setPeriod(int period) {
    
        this.period = period;
    }
    
}
